﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JsonTest1.Data;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace JsonTest1.Json
{
    public class ReviewBuilder: JSONBuilder<Review>
    {

        public override Review Build(JObject jsonObject)
        {
            Review data = new Review();

            data.Id = (int)jsonObject["id"];
            data.Lang = (string)jsonObject["lang"];
            data.Name = (string)jsonObject["name"];
            try
            {
                data.Rating = (int)jsonObject["rating"];
            }
            catch (JsonException e)
            {
                // this may happen and rating can be set to null
                data.Rating = 0;
            }
           
            data.Name = ((string)jsonObject["text"]).Replace("\r","");
            data.Lang = (string)jsonObject["user_image"];
            data.Name = (string)jsonObject["user_name"];

            return data;
        }
    }
}
